#
# Makefile for the ESP Package Manager (EPM) documentation.
#
# Copyright © 1999-2020 by Michael R Sweet
# Copyright © 1999-2006 by Easy Software Products, all rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#

# Programs...
CC	=	@CC@
HTMLDOC	=	@HTMLDOC@
RM	=	@RM@ -f


# Program options...
ARFLAGS		=	@ARFLAGS@
ARCHFLAGS	=	@ARCHFLAGS@
CFLAGS		=	$(ARCHFLAGS) @CFLAGS@ $(OPTIM)
CPPFLAGS	=	@CPPFLAGS@
LDFLAGS		=	$(ARCHFLAGS) @LDFLAGS@ $(OPTIM)
LIBS		=	@LIBS@
OPTIM		=	@OPTIM@


# Directories...
bindir		=	@bindir@
datadir		=	@datadir@
datarootdir	=	@datarootdir@
exec_prefix	=	@exec_prefix@
includedir	=	@includedir@
infodir		=	@infodir@
libdir		=	@libdir@
libexecdir	=	@libexecdir@
localstatedir	=	@localstatedir@
mandir		=	@mandir@
oldincludedir	=	@oldincludedir@
prefix		=	@prefix@
privateinclude	=	@privateinclude@
sbindir		=	@sbindir@
sharedstatedir	=	@sharedstatedir@
srcdir		=	@srcdir@
sysconfdir	=	@sysconfdir@
top_srcdir	=	@top_srcdir@

BUILDROOT	=	$(DSTROOT)$(RPM_BUILD_ROOT)$(DESTDIR)
VPATH		=	$(srcdir)


# Man page generation rule...
.SUFFIXES:	.html .1 .5
.1.html .5.html:
	$(RM) $@
	./mantohtml $< >$@


# Targets...
MANPAGES	=	epm.html epminstall.html mkepmlist.html setup.html
HTMLFILES	=	title.html preface.html 1-intro.html 2-building.html \
			3-packaging.html 4-advanced.html 5-examples.html \
			a-license.html b-manpages.html c-reference.html \
			$(MANPAGES)
BOOKS		=	epm-book.epub epm-book.html epm-book.pdf


# Make everything (requires HTMLDOC)
all:	$(MANPAGES) $(BOOKS)

# Clean generated programs
clean:
	$(RM) mantohtml mantohtml.o

# Install documentation
install:
	echo Installing EPM manpages in $(BUILDROOT)$(mandir)/man1
	$(INSTALL) -d -m 755 $(BUILDROOT)$(mandir)/man1
	for file in epm.1 epminstall.1 mkepmlist. setup.1; do \
		$(INSTALL) -c -m 644 $$file $(BUILDROOT)$(mandir)/man1; \
	done
	echo Installing EPM manpages in $(BUILDROOT)$(mandir)/man5
	$(INSTALL) -d -m 755 $(BUILDROOT)$(mandir)/man5
	for file in epm.list.5 setup.types.5; do \
		$(INSTALL) -c -m 644 $$file $(BUILDROOT)$(mandir)/man5; \
	done
	echo Installing EPM documentation in $(BUILDROOT)$(docdir)
	$(INSTALL) -d -m 755 $(BUILDROOT)$(docdir)
	for file in $(srcdir)/COPYING $(srcdir)/README.md $(BOOKS); do \
		$(INSTALL) -c -m 644 $$file $(BUILDROOT)$(docdir); \
	done


# Uninstall all targets...
uninstall:
	echo Uninstalling EPM manpages from $(BUILDROOT)$(mandir)/man1
	$(RM) $(BUILDROOT)$(mandir)/man1/epm.1
	$(RM) $(BUILDROOT)$(mandir)/man1/epminstall.1
	$(RM) $(BUILDROOT)$(mandir)/man1/mkepmlist.1
	$(RM) $(BUILDROOT)$(mandir)/man1/setup.1
	echo Uninstalling EPM manpages from $(BUILDROOT)$(mandir)/man5
	$(RM) $(BUILDROOT)$(mandir)/man5/epm.list.5
	$(RM) $(BUILDROOT)$(mandir)/man5/setup.types.5
	echo Uninstalling EPM documentation from $(BUILDROOT)$(docdir)
	$(RM) -r $(BUILDROOT)$(docdir)

# EPUB book
epm-book.epub:	$(HTMLFILES) epm-256.png setup.png title.png epm-book.book
	$(HTMLDOC) --batch epm-book.book --titleimage title.png -f epm-book.epub

# HTML book
epm-book.html:	$(HTMLFILES) epm-256.png setup.png epm-book.book
	$(HTMLDOC) --batch epm-book.book -f epm-book.html

# PDF book
epm-book.pdf:	$(HTMLFILES) epm-256.png setup.png epm-book.book
	$(HTMLDOC) --batch epm-book.book --size universal -f epm-book.pdf

# mantohtml
mantohtml:	mantohtml.o
	$(CC) -o $@ mantohtml.o

# HTML man pages
$(MANPAGES):	mantohtml
